/*
 * @Description: 你的代码我的心
 * @Author: GGB
 * @Date: 2022-01-24 11:12:33
 * @LastEditors: GGB
 * @LastEditTime: 2022-01-26 13:50:11
 */
import { defHttp } from '/@/utils/http/axios';
import {
  LoginParams,
  LoginResultModel,
  GetUserInfoModel,
  UpdateAdminParams,
} from './model/userModel';
import { BasicResult } from '../model/baseModel';

import { ErrorMessageMode } from '/#/axios';

enum Api {
  Login = '/passport/login',
  Logout = '/passport/logout',
  GetUserInfo = '/admin.user/detail',
  GetPermCode = '/getPermCode',
  UpdateAdminInfo = '/admin.user/renew',
  getAdminInfo = '/admin.user/detail',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}

/**
 * @description:update admin api
 */
export function updateAdminAccount(params: UpdateAdminParams) {
  return defHttp.post<BasicResult>({
    url: Api.UpdateAdminInfo,
    params,
  });
}
export function getAdminInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.getAdminInfo }, { errorMessageMode: 'none' });
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo }, { errorMessageMode: 'none' });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}

export function doLogout() {
  return defHttp.get({ url: Api.Logout });
}
